<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
	<div region="center" style="padding: 0px; border: 0px">
		<t:datagrid name="wxMediaList" checkbox="true" fitColumns="false"
			title="微信多媒体素材"
			actionUrl="wxMediaController.do?datagrid&type=${type}" idField="id"
			fit="true" queryMode="group">
			<t:dgCol title="主键" field="id" hidden="true" queryMode="single"
				width="120"></t:dgCol>
			<t:dgCol title="创建人名称" field="createName" hidden="true"
				queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="创建人登录名称" field="createBy" hidden="true"
				queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="更新人名称" field="updateName" hidden="true"
				queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="更新人登录名称" field="updateBy" hidden="true"
				queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="更新日期" field="updateDate" formatter="yyyy-MM-dd"
				hidden="true" queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="所属部门" field="sysOrgCode" hidden="true"
				queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="所属公司" field="sysCompanyCode" hidden="true"
				queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="类型" field="type" queryMode="single"
				dictionary="wxmediatype" width="120"></t:dgCol>
			<t:dgCol title="素材名称" field="templateName" queryMode="single"
				width="120"></t:dgCol>
			<t:dgCol title="文件名称" field="fileName" url="true" queryMode="single"
				formatterjs="fmtFileName"></t:dgCol>
			<t:dgCol title="文件原始名称" field="fileRawName" hidden="true" url="true"
				queryMode="single"></t:dgCol>
			<t:dgCol title="描述" field="description" queryMode="single"
				width="120"></t:dgCol>
			<t:dgCol title="创建日期" field="createDate" formatter="yyyy-MM-dd"
				queryMode="single" width="120"></t:dgCol>
			<t:dgCol title="是否上传微信" field="mediaId" queryMode="single"
				width="120" formatterjs="fmtMediaId"></t:dgCol>
			<t:dgCol title="操作" field="opt" width="100"></t:dgCol>
			<t:dgDelOpt title="删除" url="wxMediaController.do?doDel&id={id}" />
			<t:dgFunOpt title="上传" exp="mediaId#empty#true"
				funname="uploadOne(id)"></t:dgFunOpt>
			<t:dgToolBar title="录入" icon="icon-add"
				url="wxMediaController.do?goAdd&type=${type}" funname="add"></t:dgToolBar>
			<t:dgToolBar title="编辑" icon="icon-edit"
				url="wxMediaController.do?goUpdate&type=${type}" funname="update"></t:dgToolBar>
			<t:dgToolBar title="批量删除" icon="icon-remove"
				url="wxMediaController.do?doBatchDel" funname="deleteALLSelect"></t:dgToolBar>
			<t:dgToolBar title="批量上传" icon="icon-remove"
				url="wxMediaController.do?doBatchUpload" funname="uploadAllSelect"></t:dgToolBar>
			<t:dgToolBar title="查看" icon="icon-search"
				url="wxMediaController.do?goUpdate" funname="detail"></t:dgToolBar>
			<t:dgToolBar title="导入" icon="icon-put" funname="ImportXls"></t:dgToolBar>
			<t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
			<t:dgToolBar title="模板下载" icon="icon-putout" funname="ExportXlsByT"></t:dgToolBar>
		</t:datagrid>
	</div>
</div>
<script src="webpage/com/gomore/wechat/module/media/wxMediaList.js"></script>
<script type="text/javascript">
  $(document).ready(
      function() {
        //给时间控件加上样式
        $("#wxMediaListtb").find("input[name='createDate']").attr("class",
            "Wdate").click(function() {
          WdatePicker({
            dateFmt : 'yyyy-MM-dd'
          });
        });
        $("#wxMediaListtb").find("input[name='updateDate']").attr("class",
            "Wdate").click(function() {
          WdatePicker({
            dateFmt : 'yyyy-MM-dd'
          });
        });
      });

  function fmtFileName(value, row, index) {
    if (row.type == 'image') {
      return "<img src='" + value + "' style='width:40px; height:40px; text-align:center'>";
    } else {
      return "<a href='" + value + "' style='color:blue;text-decoration: underline;'>"
          + row.fileRawName + "</a>";
    }
  }

  function fmtMediaId(value, row, index) {
    return value ? "已上传" : "<font color='red'>未上传</font>";
  }

  function uploadOne(id) {
    $.dialog.confirm('你确定上传该数据吗?', function(r) {
      if (r) {
        var ids = [];
        ids.push(id);
        uploadAll(ids);
      }
    });
  }

  function uploadAllSelect(title, url, gname) {
    gridname = gname;
    var ids = [];
    var rows = $("#" + gname).datagrid('getSelections');
    for (var i = 0; i < rows.length; i++) {
      ids.push(rows[i].id);
    }
    if (ids.length <= 0) {
      tip("请选择需要上传的数据");
      return;
    }

    $.dialog.setting.zIndex = getzIndex(true);
    $.dialog.confirm('你确定上传该文件吗?', function(r) {
      if (r) {
        uploadAll(ids);
      }
    });
  }

  function uploadAll(ids) {
    $.ajax({
      url : "wxMediaController.do?doBatchUpload",
      type : 'post',
      data : {
        ids : ids.join(',')
      },
      cache : false,
      success : function(data) {
        var d = $.parseJSON(data);
        if (d.success) {
          var msg = d.msg;
          tip(msg);
          reloadTable();
          $("#wxMediaList').datagrid('unselectAll');
          ids = '';
        } else {
          tip("上传失败: " + d.msg);
        }
      }
    });
  }

  //导入
  function ImportXls() {
    openuploadwin('Excel导入', 'wxMediaController.do?upload', "wxMediaList");
  }

  //导出
  function ExportXls() {
    JeecgExcelExport("wxMediaController.do?exportXls", "wxMediaList");
  }

  //模板下载
  function ExportXlsByT() {
    JeecgExcelExport("wxMediaController.do?exportXlsByT", "wxMediaList");
  }
</script>